package 剑指offer;

import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @author zhangjunfei
 * @date 2023/8/30 16:39
 */
public class O_59_02 {

    Queue<Integer> A = new ArrayDeque<>();
    Queue<Integer> B = new LinkedList<>();

    public int max_value() {
        if (A.isEmpty()) {
            return -1;
        }
        return B.peek();
    }

    public void push_back(int value) {
        A.add(value);
        if (B.isEmpty() || value >= B.peek()) {
            B.add(value);
        }
    }

    public int pop_front() {
        if (A.isEmpty()) {
            return -1;
        }
        Integer poll = A.poll();
        if (poll.equals(B.peek())) {
            B.poll();
        }
        return poll;
    }
}
